﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using Public;

namespace Dal
{
    public class Series
    {
        public static DataTable MULTIPLE(string strCon)
        {
            DataTable dt = new DataTable();
            dt.Locale = CultureInfo.InvariantCulture;

            try
            {
                dt = SqlHelper.ExecuteDataTable(DataProtector.DecryptString(strCon), CommandType.StoredProcedure, "SP_Series_List_MULTIPLE");
            }
            catch
            {
                throw;
            }
            return dt;
        }


        public static DataTable MULTIPLE(string strCon, int strCatID)
        {
            DataTable dt = new DataTable();
            dt.Locale = CultureInfo.InvariantCulture;
            SqlParameter[] pars = new SqlParameter[1];
            pars[0] = new SqlParameter("@CatID", SqlDbType.Int);
            pars[0].Value = strCatID;

            try
            {
                dt = SqlHelper.ExecuteDataTable(DataProtector.DecryptString(strCon), CommandType.StoredProcedure, "SP_Series_MULTIPLE", pars);
            }
            catch
            {
                throw;
            }
            return dt;
        }
        public static DataTable MULTIPLE_Pro(string strCon,int id) 
        {
            DataTable dt = new DataTable();
            dt.Locale = CultureInfo.InvariantCulture;
            SqlParameter[] pars = { new SqlParameter("@CatID", id) };
            try
            {
                dt = SqlHelper.ExecuteDataTable(DataProtector.DecryptString(strCon), CommandType.StoredProcedure, "SP_Series_List_MULTIPLE_CatID", pars);
            }
            catch (Exception)
            {
                dt = null;
            }
            return dt;

        }

        public static DataTable Single(string strCon, int pkid)
        {
            DataTable dt = new DataTable();
            dt.Locale = CultureInfo.InvariantCulture;
            SqlParameter[] pars = new SqlParameter[1];
            pars[0] = new SqlParameter("@PKID", SqlDbType.Int);
            pars[0].Value = pkid;

            try
            {
                dt = SqlHelper.ExecuteDataTable(DataProtector.DecryptString(strCon), CommandType.StoredProcedure, "SP_Series_SINGLE_PKID", pars);
            }
            catch
            {
                throw;
            }
            return dt;
        }


        public static int Update(string strCon,
                int txbCatID,
                string txbSerTitle,
                string txbDescription,
                string txbImgURL,
                int txbSortBy,
                int txbPKID)
        {
            int rtn = 0;
            SqlParameter[] pars = new SqlParameter[6];
            pars[0] = new SqlParameter("@CatID", SqlDbType.Int);
            pars[0].Value = txbCatID;
            pars[1] = new SqlParameter("@SeriesName", SqlDbType.NVarChar, 50);
            pars[1].Value = txbSerTitle;
            pars[2] = new SqlParameter("@Description", SqlDbType.NVarChar,2000);
            pars[2].Value = txbDescription;
            pars[3] = new SqlParameter("@ImgURL", SqlDbType.NVarChar);
            pars[3].Value = txbImgURL;
            pars[4] = new SqlParameter("@SortBy", SqlDbType.TinyInt);
            pars[4].Value = txbSortBy;
            pars[5] = new SqlParameter("@PKID", SqlDbType.Int);
            pars[5].Value = txbPKID;

            try
            {
                rtn = SqlHelper.ExecuteNonQuery(DataProtector.DecryptString(strCon), CommandType.StoredProcedure, "SP_Series_UPDATE", pars);
            }
            catch
            {
                throw;
            }
            return rtn;
        }

        public static int Insert(string strCon,
                int txbCatID,
                string txbSerTitle,
                string txbDescription,
                string txbImgURL,
                int txbSortBy)
        {
            int rtn = 0;
            SqlParameter[] pars = new SqlParameter[5];
            pars[0] = new SqlParameter("@CatID", SqlDbType.Int);
            pars[0].Value = txbCatID;
            pars[1] = new SqlParameter("@SeriesName", SqlDbType.NVarChar, 50);
            pars[1].Value = txbSerTitle;
            pars[2] = new SqlParameter("@Description", SqlDbType.NVarChar, 2000);
            pars[2].Value = txbDescription;
            pars[3] = new SqlParameter("@ImgURL", SqlDbType.NVarChar);
            pars[3].Value = txbImgURL;
            pars[4] = new SqlParameter("@SortBy", SqlDbType.TinyInt);
            pars[4].Value = txbSortBy;

            try
            {
                rtn = SqlHelper.ExecuteNonQuery(DataProtector.DecryptString(strCon), CommandType.StoredProcedure, "SP_Series_INSERT", pars);
            }
            catch
            {
                throw;
            }
            return rtn;
        }

        public static int Delete(string strCon, int pkid)
        {
            int rtn = 0;
            SqlParameter[] pars = new SqlParameter[1];
            pars[0] = new SqlParameter("@PKID", SqlDbType.SmallInt);
            pars[0].Value = pkid;
            try
            {
                rtn = SqlHelper.ExecuteNonQuery(DataProtector.DecryptString(strCon), CommandType.StoredProcedure, "SP_Series_DELETE", pars);
            }
            catch
            {
                throw;
            }
            return rtn;
        }
    }
}
